package com.delivery.www.servlet;

import com.delivery.www.po.Seller;
import com.delivery.www.service.ServiceImpl.StoreServiceImpl;

import java.util.Scanner;

import static com.delivery.www.servlet.Menu.menu;
import static com.delivery.www.servlet.SellerStorePage.storePage;

public class SellerPage {
    public static void sellerPage(Seller seller) {
        System.out.println("============请选择你所需要的服务============");
        System.out.println("1.查看自己的信息");
        System.out.println("2.查看自己店铺");
        System.out.println("3.退出");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        while (i != 1 && i != 2 && i != 3) {
            System.out.println("输入错误！请重新输入");
            i = scanner.nextInt();
        }
        if (i == 1) {
            System.out.println("您的信息如下：");
            System.out.println("用户名:" + seller.getSellerName());
            System.out.println("邮箱:" + seller.getSellerEmail());
            System.out.println("返回请按0");
            int i1 = scanner.nextInt();
            while (i1 != 0) {
                System.out.println("输入错误！请重新输入");
                i1 = scanner.nextInt();
            }
            sellerPage(seller);
        }
        if (i == 3) {
            menu();
        }
        if (i == 2) {
            if (seller.getStoreId() == 0) {
                System.out.println("您还没有店铺，是否前往创建");
                System.out.println("1.是");
                System.out.println("2.否");
                int i1 = scanner.nextInt();
                while (i1 != 1 && i1 != 2) {
                    System.out.println("输入错误！请重新输入");
                    i1 = scanner.nextInt();
                }
                if (i1 == 2) {
                    sellerPage(seller);
                } else {
                    StoreServiceImpl storeService = new StoreServiceImpl();
                    System.out.println("请输入店铺名");
                    String name = scanner.next();
                    System.out.println("请输入店铺简介");
                    String introduce = scanner.next();
                    boolean b = storeService.createStore(name, introduce, seller.getSellerId());
                    if (b) {
                        System.out.println("创建成功");
                        sellerPage(seller);
                    }
                }
            } else {
                storePage(seller);
            }
        }
    }
}
